package EA;

/** Abstract class for the contents of the nodes in a TreeGenome tree. The
    TreeGenomeContents class represents the different types of contents a
    TreeGenome node can contain. This includes not only operators but also
    the contents of leaves in the tree, i.e. constants, inputvariables etc.
    <br>Subclass this for each of your operators, constants and 
    inputvariables when implementing your EA. 
*/
public class TreeGenomeContents implements Cloneable
{
  /** A possible container this TreeGenomeContents is a part of. A container
      can be any object and can be used to extract information from. E.g.
      the Individual this TreeGenomeContents is a part of which might hold 
      variables needed by the TreeGenomeContents.
  */
  public Object container;

  public boolean isvariable;

  public TreeGenomeContents()
    {
      super();
      isvariable = false;
    }


  public TreeGenomeContents(Object thecontainer)
    {
      super();
      container = thecontainer;
      isvariable = false;
    }

  /** Create a copy of this TreeGenomeContents with random initialization. 
      This is called when a random tree
      is generated. (See the TreeGenome class for an explanation on how
      this is done.)<br> When subclassing the 
      TreeGenomeContents class you should override this method so it 
      fits your operator. If your tree for instance represents realvalued 
      functions and have a subclass of the TreeGenomeContents implementing 
      constants, then this method can return a constant object where the
      value of the constant is set to some random value.
      @see TreeGenome
  */
  public TreeGenomeContents randomContents(Object thecontainer)
    {
      return this;
    }

  /** Get the number of arguments this operator takes. Returns 0 if the
      TreeGenomeContents represents a leaf in the TreeGenome, 1 if the
      operator is an unary operator, 2 if it is binary etc.<br>
      <b>NOTE:</b> At least one of your subclasses of TreeGenomeContents must
      return 0, otherwise the generation of random trees will fail 
      or loop infinitely.
  */      
  public int numberOfArguments()
    {
      return 0;
    }

  /** Evaluate the operator for this TreeGenomeContents. 
      This is called from TreeGenome.evaluate()<br>Override this with your
      chosen operator.
      @param arguments Array of arguments to the operator. E.g. an array of Doubles if you are building functions of real values.
  */
  public Object evaluate(Object[] arguments)
    {
      return new Object();
    }

  /** Return the constant/variable for this TreeGenome node. This is called
      when a TreeGenome has no sons. 
  */
  public Object evaluate()
    {
      return new Object();
    }

  /** Return a string representing this operator applied to its operators.
      @param arguments An array of strings representing this operators subexpressions.
  */
  public String toString(String[] arguments)
    {
      return "";
    }

  public String toString()
    {
      return toString(new String[0]);
    }


  /** Clone this TreeGenomeContents. You must override this method when 
      subclassing the TreeGenomeContents. It is called from cloneTree() in 
      the TreeGenome class.
      @see TreeGenome#cloneTree
  */
  public Object clone()
    {
      return this;
    }

  /** Clone this TreeGenomeContents. You must override this method when 
      subclassing the TreeGenomeContents. It is called from cloneTree() in 
      the TreeGenome class.
      @see TreeGenome#cloneTree
  */
  public Object clone(Object thecontainer)
    {
      return this;
    }

  /** Return this TreeGenomeContents as a fastevaluation contents. This can
      e.g. be used for functionplotting and must be overridden if you want 
      to use the fast-evaluation.
  */
  public TreeGenomeFastEval getAsFastEvaluation()
    {
      return null;
    }

}
